package Homeworks.HOMEWORK0301;

import java.util.Random;
import java.util.Scanner;

public class Work4 {
    public static void main(String[] args) {
        String[] names = {"宋一", "李二", "张三", "李四", "王五", "小华", "约翰", "王朝", "马汉", "张龙", "赵虎"};
        printStudentName(names);
        String name = randomStudentName(names);
        System.out.println("随机点取到的同学:" + name);
        int n=1;
        char ch;
        while (n>0){
            System.out.println("你是否还要随机点取：");
            Scanner sc = new Scanner(System.in);
            ch = sc.next().charAt(0);

            if (ch=='y'){
                name = randomStudentName(names);
                System.out.println("随机点取到的同学:" + name);
            }
            else if (ch=='n'){
                break;
            }
        }

    }
    public static void printStudentName(String[] names) {
        //遍历数组
        for (int i = 1; i < names.length; i++) {
            System.out.print(names[i]+" ");
            if(i%5==0){
                System.out.println();
            }
        }
    }
    public  static String randomStudentName(String[] names){
        Random ran =new Random();
        int index =ran.nextInt(names.length);
        return   names[index];

    }
}

